package snippet;
import java.io.*;
import java.util.*;
public class _01背包 {
	public static void main(String[] args) throws IOException {
		int N = 5010;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int m = Integer.parseInt(st.nextToken());
		
		int w[] = new int[N];
		int v[] = new int[N];
		
		st = new StringTokenizer(br.readLine());
		for(int i = 1; i <= n ; i++) {
			w[i] = Integer.parseInt(st.nextToken());
		}
		st = new StringTokenizer(br.readLine());
		for(int i = 1; i <= n; i++) {
			v[i] = Integer.parseInt(st.nextToken());
		}
		
		int dp[][] = new int[n+1][m+1];
		int res = 0;
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= m; j++) {
				if(w[i] > j) {
					dp[i][j] = dp[i-1][j];
				} else {
					dp[i][j] = Math.max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
				}
				res = Math.max(res, dp[i][j]);
			}

		}
		System.out.println(res);
	}
}
